package com.kingint.web.portal.data.controller;


import com.kingint.mbg.group.Insert;
import com.kingint.mbg.group.Update;
import com.kingint.web.util.validateUtil.ValidList;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.kingint.common.unitedresult.K;

import com.kingint.web.portal.data.service.DataCustomerPreferenceService;
import com.kingint.mbg.data.entity.DataCustomerPreference;


/**
 * @描述：客人偏好统计表控制类
 * @作者: wxh
 * @日期: 2021-01-23
 */
@RestController
@RequestMapping("/dataCustomerPreference")
@Api(value = "DataCustomerPreferenceController", description = "客人偏好统计表")
@CrossOrigin
public class DataCustomerPreferenceController{

    @Autowired
    public DataCustomerPreferenceService dataCustomerPreferenceService;


    @ApiOperation(value = "添加客人偏好统计表")
    @PostMapping("/create")
    public Object create(@Validated(Insert.class) @RequestBody DataCustomerPreference dataCustomerPreference){
        Boolean bool=dataCustomerPreferenceService.saveOrUpdate(dataCustomerPreference);
        if(bool){
            return K.ok().data(dataCustomerPreference.getId());
        }else{
            return K.error();
        }
    }

    @ApiOperation(value = "批量添加客人偏好统计表")
    @PostMapping("/insertList")
    public Object create(@RequestBody @Validated(Insert.class)  ValidList<DataCustomerPreference> dataCustomerPreference){
        Boolean bool=dataCustomerPreferenceService.saveOrUpdateBatch(dataCustomerPreference);
        if(bool){
            return K.ok();
        }else{
            return K.error();
        }
    }

    @ApiOperation(value = "更新客人偏好统计表")
    @PutMapping("/update")
    public Object update(@Validated(Update.class) @RequestBody DataCustomerPreference dataCustomerPreference){
        Boolean bool= dataCustomerPreferenceService.updateById(dataCustomerPreference);
        if(bool){
             return K.ok().data(dataCustomerPreference.getId());
        }else{
             return K.error();
        }
    }


    @ApiOperation(value = "删除客人偏好统计表")
    @DeleteMapping("/delete/{id}")
    public Object delete(@PathVariable("id") Long id){
        Boolean bool= dataCustomerPreferenceService.removeById(id);
        if(bool){
            return K.ok();
        }else{
            return K.error();
        }
    }

    @ApiOperation(value = "根据客人偏好统计表名称分页获取客人偏好统计表列表")
    @GetMapping("/list")
    public Object getList(DataCustomerPreference dataCustomerPreference,
    @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
    @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize){
        Page<DataCustomerPreference> page = new Page<>(pageNum, pageSize);
        IPage<DataCustomerPreference> info=dataCustomerPreferenceService.page(page,null);
        return K.ok().data(info);
    }

    @ApiOperation(value = "根据编号查询客人偏好统计表信息")
    @GetMapping("/{id}")
    public Object getItem(@PathVariable("id") Long id){
        DataCustomerPreference dataCustomerPreference=dataCustomerPreferenceService.getById(id);
        return K.ok().data(dataCustomerPreference);
    }

    @ApiOperation(value = "查询统计信息")
    @GetMapping("/getinfo")
    public Object getInfo(){
        return K.ok().data(dataCustomerPreferenceService.getDataFrontBackInfo());
    }
}